package com.jiepos.mpos.common.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.jiepos.mpos.common.constant.DBConstant.Table;
import com.jiepos.mpos.common.entity.App_Log_Four_ElementsEntity;
import com.jiepos.mpos.core.dao.BaseDao;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * 
 * 四要素认证数据接口层
 * 
 * @ProjectName: [mpos1]
 * @Package com.jiepos.mpos.common.dao
 * @author 肖志伟
 * @version 1.0
 * @since 2017年9月27日 下午2:43:43
 * @history（历次修订内容、修订人、修订时间等） @UpdateRemark [说明本次修改内容]
 * @Copyright (c) 2017 江苏杰博实信息技术有限公司
 */
@Repository
public class LogFourElementsDao extends BaseDao<App_Log_Four_ElementsEntity> {

	/**
	 * 根据四要素数据获取表中数据
	 * 
	 * @param name
	 * @param phone
	 * @param certificate_no
	 * @param acct_no
	 * @return
	 */
	public App_Log_Four_ElementsEntity findByMultiParams(Map<String, String> map) {
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT * FROM " + Table.T_APP_LOG_FOUR_ELEMENTS + " WHERE 1=1 AND REC_ST!='0' ");
		List list = new ArrayList();
		for(Map.Entry<String, String> entry : map.entrySet()){
			if(!StringUtils.isBlank(entry.getValue())){
				sb.append(" and UPPER("+entry.getKey()+") = ? ");
				list.add(entry.getValue());
			}
		}
		sb.append(" ORDER BY REC_ID DESC ");
		log.debug(sb.toString());
		RowMapper<App_Log_Four_ElementsEntity> rowMapper = BeanPropertyRowMapper
				.newInstance(App_Log_Four_ElementsEntity.class);
		List<App_Log_Four_ElementsEntity> appLogFourElementsEntityList = jdbcTemplate.query(sb.toString(), rowMapper,
				list.toArray());

		if (appLogFourElementsEntityList != null && appLogFourElementsEntityList.size() > 0) {
			return appLogFourElementsEntityList.get(0);
		}
		return null;
	}

}
